package com.edu.hre.db.sql.leave;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts.util.LabelValueBean;

import com.edu.hre.common.utils.BeanFinder;
import com.edu.hre.common.utils.CommonUtils;
import com.edu.hre.db.service.BaseService;

public class LeaveRequestDAOService {
	
	public static final String BEAN_NAME = "leaveRequestDAOService";
	private BaseService baseService = null;
	
	public BaseService getBaseService() {
		return baseService;
	}
	public void setBaseService(BaseService baseService) {
		this.baseService = baseService;
	}

	public List<LabelValueBean> getSupervisorsOfEmp (String id) {
		String sql = "SELECT CONCAT(sup.emp_lastname, ' ', sup.emp_middle_name, ' ', sup.emp_firstname) AS col1 " +
					" , sup.emp_number AS col2, sup.main_username AS col3 " +
					" FROM hre_emp_reportto AS rep" +
					" LEFT OUTER JOIN hre_employee AS emp ON rep.erep_sub_emp_number = emp.emp_number" +
					" LEFT OUTER JOIN hre_employee AS sup ON rep.erep_sup_emp_number = sup.emp_number" +
					" WHERE sup.is_deleted = 0 " +
					" AND emp.emp_number = ?";
		List <Object[]> listObject = baseService.listArrayObject(sql, 0, 0, id);
		List <LabelValueBean> listSupvs = new ArrayList<LabelValueBean>();
		for (Object[] objs: listObject) {
			try {
				String supervisorName = CommonUtils.normalizeObjectToString(objs[1], "").trim().replace("  ", " ")
						+  (objs[3] == null ? "" : " (" + (String) objs[3] + ")");
				int empNumber = (Integer) objs[2];
				listSupvs.add(new LabelValueBean(supervisorName, String.valueOf(empNumber)));
			} catch (Exception e) {
				CommonUtils.println(e.getMessage());
			}
		}
		return listSupvs;
	}
}
